package com.cty.config;

import com.cty.interceptor.MyInterceptor;
import com.cty.interceptor.MyInterceptor1;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan({"com.cty.controller","com.cty.error"})
@EnableWebMvc//该注解会为我们加入RequestMappingHandlerMapping
// ，RequestMappingHandlerAdapter 和为后者加入json处理器
public class MvcConfig implements WebMvcConfigurer  {

//    @Bean
//    public RequestMappingHandlerMapping handlerMapping(){
//        return new RequestMappingHandlerMapping();
//    }
//
//    @Bean
//    public RequestMappingHandlerAdapter  handlerAdapter(){
//        return new RequestMappingHandlerAdapter();
//    }


    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF",".jsp");
    }

    //开启静态资源处理
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    //添加拦截器
    /*
    * addPathPatterns添加路径支持模糊匹配
    * excludePathPatterns在包含的路径中去除路径
    *
    * */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //加入两个拦截器与aop的先后顺序一致
        registry.addInterceptor(new MyInterceptor());
        registry.addInterceptor(new MyInterceptor1());
    }
}
